﻿using Architecture.Domain.Service;
using Architeture.Domain;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.ZhuBoLin.Application.Command.RoleCommand;
using RBAC.ZhuBoLin.Dtos;

namespace RBAC.ZhuBoLin.Controllers
{
    /// <summary>
    /// 市
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class CityController : ControllerBase
    {
        protected readonly ICityService cityservice;
        protected readonly IMediator mediator;

        public CityController(ICityService cityservice, IMediator mediator)
        {
            this.cityservice = cityservice;
            this.mediator = mediator;
        }


        /// <summary>
        /// 返回市级（二级）
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<CityInfo>>> GetCity([FromQuery] CitySelectCommand sid)
        {
            ApiResult<List<CityInfo>> result = new ApiResult<List<CityInfo>>();
            try
            {
                result.Data = await mediator.Send(sid);
            }
            catch (Exception ex)
            {
                result.Code = 1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
    }
}
